/**
 * 修改资料
 */
import query from '../../untils/mysql';
import { Tip } from '../../untils/untils';
import { check, validationResult } from 'express-validator';
import { Sql } from './../../untils/untils';

const validator = [
    check('name').notEmpty().withMessage("昵称不能为空")
]
const POST = async (req: any, res: any, next: any) => {
    try {
        const { userId } = req.auth;
        var errors = validationResult(req);
        if (!errors.isEmpty()) {
            return Tip.tipError(res, errors.array()[0].msg);
        }
        const set = Sql.set(req.body, ["password", "phone","updateTime","createTime"]);
        await query(`update user set ${set} where id = '${userId}'`);
        return Tip.tipSuccess(res, '修改成功')
    } catch (error: any) {
        Tip.tipError500(res, error)
    }
}

export {
    POST,
    validator
}